#include "AI.h"

extern list<AdditionalInfo> additional_list;
extern list<AdditionalInfo>::iterator additional_it;

bool TimeTag(char * word, char* type)
{
	int n = 0;
	int hyphenCount = 0;
	int nowNum = 0;
	bool typeFlag = false; // if xxxx-xxxx, true

	if(strlen(word) > 10)
	{
		return false;
	}

	while(word[n] != NULL)
	{
		if(word[n] >= '0' && word[n] <= '9')
		{
			nowNum++;
		}

		else if(word[n] == '-')
		{
			hyphenCount++;

			if(hyphenCount == 1)
			{
				if(nowNum == 4)
				{
					typeFlag = true;
				}

				else if(nowNum != 2 && nowNum != 1)
				{
					return false;
				}
			}

			else if(hyphenCount == 2)
			{
				if(!typeFlag)
				{
					return false;
				}

				else if(nowNum != 2 && nowNum != 1)
				{
					return false;
				}
			}

			else if(hyphenCount == 3)
			{
				return false;
			}

			nowNum = 0;
		}

		else
		{
			return false;
		}

		n++;
	}

	if(hyphenCount == 0)
	{
		return false;
	}

	else if(nowNum != 2 && nowNum != 1)
	{
		return false;
	}

	else if(hyphenCount == 2)
	{
		strcpy_s(type, TYPE_LENGTH, "TIME_N");
		return true;
	}

	else
	{
		strcpy_s(type, TYPE_LENGTH, "TIME");

		AdditionalInfo tmp_AdditionalInfo;

		time_t times;
		tm* struct_time;
		time(&times);
		struct_time = localtime(&times);
		struct_time->tm_year;

		std::ostringstream oss;
		oss << struct_time->tm_year + 1900;

		tmp_AdditionalInfo.word = oss.str() + '-' + word;
		tmp_AdditionalInfo.type = "TIME_N";

		additional_list.push_back(tmp_AdditionalInfo);

		return true;
	}
}